package com.dd.ent.car.ui.user;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.dd.ent.car.R;
import com.dd.ent.car.common.bean.User;
import com.dd.ent.car.common.config.UIConfig;
import com.dd.ent.car.common.player.XLAlarmDialog;
import com.dd.ent.car.service.user.UserService;
import com.dd.ent.car.ui.BaseActivity;
import com.duanqu.qupai.utils.ToastUtils;
import com.pp.ent.core.manage.UIHandler;
import com.pp.ent.view.annotation.ContentView;
import com.pp.ent.view.annotation.Inject;
import com.pp.ent.view.annotation.OnClick;
import com.pp.ent.view.annotation.ViewInject;

/**
 * Created by dengqu on 17/10/14.
 */

@ContentView(R.layout.activity_setting_layout)
public class SettingActivity extends BaseActivity {

    private XLAlarmDialog xlAlarmDialog;
    @Inject
    private UserService userService;

    public static void startSelf(Context context) {
        Intent intent = new Intent(context, SettingActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @OnClick({R.id.tv_login_out})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_login_out:
                tryExit();
                break;
        }
    }

    private void tryExit() {
        if (xlAlarmDialog == null) {
            xlAlarmDialog = new XLAlarmDialog(this);
            xlAlarmDialog.setContent("确定退出？");
            xlAlarmDialog.setOnClickCancelButtonListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    xlAlarmDialog.dismiss();

                }
            });
            xlAlarmDialog.setOnClickConfirmButtonListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    xlAlarmDialog.dismiss();
                    userService.loginOut();
                }
            });
        } else {
            xlAlarmDialog.dismiss();
        }
        xlAlarmDialog.show();
    }

    @UIHandler(UIConfig.NOTIFY_LOGIN_OUT_SUCCESS)
    public void onLoginOutSuccessResponse() {
        ToastUtils.showToast(this, "退出登录成功");
        finish();
    }

    @UIHandler(UIConfig.NOTIFY_LOGIN_OUT_FAIL)
    public void onLoginOutFailResponse() {
        ToastUtils.showToast(this, "退出登录失败");
    }
}
